/*
 * Created on 2005-4-26
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package nc.tb.ufo.ui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import nc.tb.pub.lang.NtbUILangRes;
import nc.tb.pub.util.NtbLogger;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pub.beans.UIPanel;
/**
 * @author tzj
 * 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
 */
public class NoteDialog extends UIDialog implements ActionListener {
	/** Note */
	private String m_Note = null;
	/** TextArea for edit */
	private JTextArea m_JTextArea = new JTextArea();
	private UIPanel pnlMain = new UIPanel();
	private UIPanel pnlBottom = new UIPanel();
	private UIButton btnOK = new UIButton(NtbUILangRes.getInstance().getStrByID("UPPntbui-000059"));
	private UIButton btnCancel = new UIButton(NtbUILangRes.getInstance().getStrByID("UPPntbui-000005"));

	public NoteDialog() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param parent
	 */
	public NoteDialog(Container parent) {
		super(parent);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param parent
	 * @param title
	 */
	public NoteDialog(Container parent, String title) {
		super(parent, title);
		init();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param owner
	 */
	public NoteDialog(Frame owner) {
		super(owner);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param owner
	 * @param title
	 */
	public NoteDialog(Frame owner, String title) {
		super(owner, title);
		// TODO Auto-generated constructor stub
	}

	private void init() {
		setSize(300, 200);
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(pnlMain, BorderLayout.CENTER);
		pnlMain.setLayout(new BorderLayout());
		JScrollPane js = new JScrollPane();
		js.setViewportView(m_JTextArea);
		m_JTextArea.setLineWrap(true);
		m_JTextArea.setWrapStyleWord(true);
		pnlMain.add(js);
		pnlBottom.setPreferredSize(new Dimension(0, 30));
		getContentPane().add(pnlBottom, BorderLayout.SOUTH);
		pnlBottom.setLayout(new FlowLayout());
		pnlBottom.add(btnOK);
		pnlBottom.add(btnCancel);
		btnOK.addActionListener(this);
		btnCancel.addActionListener(this);
		NtbLogger.print4("Init");
	}

	public void setNote(String note) {
		m_JTextArea.setText(note);
	}

	public String getNote() {
		return m_Note;
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() == btnOK) {
			if (m_JTextArea.getText() == null) {
				m_Note = null;
			} else {
				m_Note = (m_JTextArea.getText() + "").trim();
				if (m_Note.toCharArray().length > 270){
					MessageDialog.showErrorDlg(this,NtbUILangRes.getInstance().getStrByID("UPPntbui-000042"),NtbUILangRes.getInstance().getStrByID("UPPntbui-002075"));
					return;
				}
				if(m_Note.length()==0)m_Note=null;
			}
			closeOK();
		} else if (e.getSource() == btnCancel) {
			closeCancel();
		}
	}
}